#include<stdio.h>
#include<stdlib.h>
#include<string.h>

FILE	*inf;
long	caseN;
int		c,r,stR,stC;// startI,startJ
char	laby[1002][1002];
short int	move[4][2]={{-1,0},{+1,0},{0,-1},{0,+1}};
long	maxLen;

long	DFSMaxLen(int rr,int cc){

	int	i,newR,newC;
	long btrLen,bstLen;//better length,best length
	
	bstLen=0;
	for (i=0; i<4; i++) {
		btrLen=0;
		newR=rr+move[i][0];
		newC=cc+move[i][1];
		if (laby[newR][newC]!=0) {
			laby[newR][newC]=0;
			btrLen=DFSMaxLen(newR,newC)+1;
		}  
		if (btrLen+bstLen>maxLen) maxLen=btrLen+bstLen;
		if (btrLen>bstLen) bstLen=btrLen;
	}
	return bstLen;
}

main(){

	char	str[1002];
	int		i,j;

//	inf=fopen("2013.in","r");
	inf=stdin;
	fscanf(inf,"%ld",&caseN);
	for (long caseI=0; caseI<caseN; caseI++) {
		memset(laby,0,sizeof(laby));
		stR=0;
		maxLen=0;
		fscanf(inf,"%d%d",&c,&r);
		for (i=1; i<=r; i++) {
			fscanf(inf,"%s",str);
			for (j=1; j<=c; j++) {				
				if (str[j-1]=='.') {
					laby[i][j]=1;
					if (stR==0) {
						stR=i;
						stC=j;
					}
				}
//				printf("%3d",laby[i][j]);
			}			
//			printf("\n");
		}
		DFSMaxLen(stR,stC);
		printf("Maximum rope length is %ld.\n",maxLen);
	}
	fclose(inf);
}